package org.fuyd.action;

import java.io.InputStream;

import org.fuyd.manager.CusQRCodeManager;
import org.fuyd.model.CusQRCode;
import org.fuyd.util.QRCodeUtil;

import com.opensymphony.xwork2.ActionSupport;

public class QRCodeAction extends ActionSupport {

  /**
	 * 
	 */
  private static final long serialVersionUID = 359629685154133571L;

  private CusQRCodeManager cusQRCodeManager; // 该成员变量是由Spring管理，用来进行注入。

  private String info; // 该成员变量用来接收页面传来的UUID

  private InputStream inputStream; // 该成员变量用于将二维码以流的形式展现给前台页面

  @Override
  public String execute() throws Exception {
    // 创建一个CusQRCode对象
    CusQRCode cusQRCode = new CusQRCode();
    cusQRCode.setQrCodeUuid(info);
    // 将该CusQRCode对象存储于数据库
    this.cusQRCodeManager.add(cusQRCode);
    // 生成一个信息为UUID，400*400的二维码图片
    this.inputStream = QRCodeUtil.createInputStream(info, 400, 400);
    return SUCCESS;
  }

  public CusQRCodeManager getCusQRCodeManager() {
    return cusQRCodeManager;
  }

  public String getInfo() {
    return info;
  }

  public InputStream getInputStream() {
    return inputStream;
  }

  public void setCusQRCodeManager(CusQRCodeManager cusQRCodeManager) {
    this.cusQRCodeManager = cusQRCodeManager;
  }

  public void setInfo(String info) {
    this.info = info;
  }

  public void setInputStream(InputStream inputStream) {
    this.inputStream = inputStream;
  }

}
